import request from '../request/request'

// 流量监控相关接口类型定义
export interface TrafficQueryParams {
  page: number
  pageSize: number
  keyword?: string
  start_time?: string
  end_time?: string
}

export interface TrafficData {
  id: number
  created_at: string
  updated_at: string
  user_id: number
  phone_id: number
  identification_numb: string
  consul_id: string
  total_traffic: number
  average_traffic: number
  total_time: number
  user_nickname: string
  deleted_at: string | null
}

export interface TrafficStatParams {
  consul_id?: string
  phone_id?: number
  user_id?: number
  start_time: string
  end_time: string
}

export interface SaveTrafficParams {
  user_id: number
  device_id: number
  device_only_code: string
  total_traffic: number
  average_traffic: number
  total_time: number
}

// 获取流量监控列表
export const getTrafficList = (params: TrafficQueryParams) => {
  return request.post<{
    code: number
    msg: string
    data: {
      list: TrafficData[]
      total: number
    }
  }>('/api/dashboard/traffic/list', params)
}

// 删除流量监控记录
export const deleteTrafficRecords = (ids: number[]) => {
  return request.post<{
    code: number
    msg: string
    data: any
  }>('/api/dashboard/traffic/delete', { ids })
}

// 获取服务器流量统计
export const getServerTrafficStats = (params: TrafficStatParams) => {
  return request.post<{
    code: number
    msg: string
    data: any
  }>('/api/dashboard/traffic/server/stat', params)
}

// 获取设备流量统计
export const getDeviceTrafficStats = (params: TrafficStatParams) => {
  return request.post<{
    code: number
    msg: string
    data: any
  }>('/api/dashboard/traffic/phone/stat', params)
}

// 获取用户流量统计
export const getUserTrafficStats = (params: TrafficStatParams) => {
  return request.post<{
    code: number
    msg: string
    data: any
  }>('/api/dashboard/traffic/user/stat', params)
}

// 统计单次使用流量
export const saveTrafficUsage = (params: SaveTrafficParams) => {
  return request.post<{
    code: number
    msg: string
    data: any
  }>('/api/dashboard/traffic/save', params)
}

